Fixing GtkCellAreaBox at render time to consider height-for-width when stacked vertically
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Fri, 26 Nov 2010 14:41:39 +0000 (23:41 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Fri, 26 Nov 2010 14:44:22 +0000 (23:44 +0900)
Also bullet-proofing GtkCellAreaBoxContext at allocate time.

gtk/gtkcellareabox.c
gtk/gtkcellareaboxcontext.c

index 522c397590d0d2ac0613a654509ca6239e367cc0..42bb934cd74381ce07acb91256f6d408fcfacfe5 100644 (file)
@@ -583,7 +583,8 @@ allocate_cells_manually (GtkCellAreaBox        *box,
   gint                      i;
   gint                      nvisible = 0, nexpand = 0, group_expand;
   gint                      avail_size, extra_size, extra_extra;
-  gint                      position = 0;
+  gint                      position = 0, for_size;
+
 
   if (!priv->cells)
     return NULL;
@@ -606,9 +607,15 @@ allocate_cells_manually (GtkCellAreaBox        *box,
     }
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-    avail_size = width;
+    {
+      avail_size = width;
+      for_size   = height;
+    }
   else
-    avail_size = height;
+    {
+      avail_size = height;
+      for_size   = width;
+    }
 
   /* Go ahead and collect the requests on the fly */
   sizes = g_new0 (GtkRequestedSize, nvisible);
@@ -619,14 +626,11 @@ allocate_cells_manually (GtkCellAreaBox        *box,
       if (!gtk_cell_renderer_get_visible (info->renderer))
        continue;
 
-      if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
-       gtk_cell_renderer_get_preferred_width_for_height (info->renderer, widget, height, 
-                                                         &sizes[i].minimum_size,
-                                                         &sizes[i].natural_size);
-      else
-       gtk_cell_renderer_get_preferred_height_for_width (info->renderer, widget, width, 
-                                                         &sizes[i].minimum_size,
-                                                         &sizes[i].natural_size);
+      gtk_cell_area_request_renderer (GTK_CELL_AREA (box), info->renderer,
+                                     priv->orientation,
+                                     widget, for_size,
+                                     &sizes[i].minimum_size,
+                                     &sizes[i].natural_size);
 
       avail_size -= sizes[i].minimum_size;
 
@@ -697,11 +701,17 @@ get_allocated_cells (GtkCellAreaBox        *box,
   GList                    *cell_list;
   GSList                   *allocated_cells = NULL;
   gint                      i, j, n_allocs;
+  gint                      for_size;
 
   group_allocs = gtk_cell_area_box_context_get_orientation_allocs (context, &n_allocs);
   if (!group_allocs)
     return allocate_cells_manually (box, widget, width, height);
 
+  if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+    for_size = height;
+  else
+    for_size = width;
+
   for (i = 0; i < n_allocs; i++)
     {
       /* We dont always allocate all groups, sometimes the requested group has only invisible
@@ -748,7 +758,7 @@ get_allocated_cells (GtkCellAreaBox        *box,
 
              gtk_cell_area_request_renderer (area, info->renderer,
                                              priv->orientation,
-                                             widget, -1,
+                                             widget, for_size,
                                              &sizes[j].minimum_size,
                                              &sizes[j].natural_size);
 
index c1e27cb2bb17bf8653b15e933887459709633011..b49ec72c38cad874a863f76ea78196780a840381 100644 (file)
@@ -492,21 +492,19 @@ gtk_cell_area_box_context_allocate (GtkCellAreaContext *context,
   orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (area));
   spacing     = gtk_cell_area_box_get_spacing (GTK_CELL_AREA_BOX (area));
 
+  g_free (priv->orientation_allocs);
+  priv->orientation_allocs   = NULL;
+  priv->n_orientation_allocs = 0;
+
   if (orientation == GTK_ORIENTATION_HORIZONTAL && width > 0)
-    {
-      g_free (priv->orientation_allocs);
-      priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
-                                                          spacing, width, height,
-                                                          &priv->n_orientation_allocs);
-    }
+    priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
+                                                        spacing, width, height,
+                                                        &priv->n_orientation_allocs);
   else if (orientation == GTK_ORIENTATION_VERTICAL && height > 0)
-    {
-      g_free (priv->orientation_allocs);
-      priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
-                                                          spacing, height, width,
-                                                          &priv->n_orientation_allocs);
-    }
-
+    priv->orientation_allocs = allocate_for_orientation (box_context, orientation, 
+                                                        spacing, height, width,
+                                                        &priv->n_orientation_allocs);
+  
   GTK_CELL_AREA_CONTEXT_CLASS (gtk_cell_area_box_context_parent_class)->allocate (context, width, height);
 }